<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\BaseAdmin;
use Illuminate\Support\Facades\Hash;

class LoginController extends Controller
{
    /**
     * 管理员列表
     */
    function login(Request $request){
   
		if($request->isMethod('post')){
    		$input = $request->all();
    		$user = BaseAdmin::where('account', '=',$input['account'])->first();

        if (!$user) {
            echo"<script>alert('用户不存在');history.go(-1);</script>";
            die;
        }

        if (!Hash::check($input['password'], $user->password)) {
            echo"<script>alert('密码不正确');history.go(-1);</script>";
            die;
        }

        //登录成功
        $request->session()->put('account',$input['account']);
     	
        return redirect('/system/base/index');
    		
    	}else{
    		return view('login.login');
    	}
    	
    }
    
    
    /**
     *退出登录 
     */
    function logout(Request $request){
    	session()->flush();
    	return redirect('/login/login');
    }
}
